import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDEquipmentUpgrade {
	/**装备等级*/
	id,
	/**升级后装备等级*/
	upgradeLv,
	/**精炼消耗道具*/
	costItem,
	/**精炼消耗*/
	costNum,
	/**强化等级降低系数*/
	strengthenReduceLow,
	/**强化等级降低系数*/
	strengthenReduceUp,
	/**成功概率2*/
	successRate_2,
	/**成功概率3*/
	successRate_3,
	/**成功概率4*/
	successRate_4,
	/**失败掉落*/
	failDropGroup_2,
	/**失败掉落*/
	failDropGroup_3,
	/**失败掉落*/
	failDropGroup_4,

	/**枚举数量*/
	EnumCount
}



export class CDEquipmentUpgrade{
	/**装备等级*/
	public id: number;
	/**升级后装备等级*/
	public upgradeLv: number;
	/**精炼消耗道具*/
	public costItem: number;
	/**精炼消耗*/
	public costNum: number;
	/**强化等级降低系数*/
	public strengthenReduceLow: number;
	/**强化等级降低系数*/
	public strengthenReduceUp: number;
	/**成功概率2*/
	public successRate_2: number;
	/**成功概率3*/
	public successRate_3: number;
	/**成功概率4*/
	public successRate_4: number;
	/**失败掉落*/
	public failDropGroup_2: number;
	/**失败掉落*/
	public failDropGroup_3: number;
	/**失败掉落*/
	public failDropGroup_4: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDEquipmentUpgrade.id: return this.id;
			case E_CDEquipmentUpgrade.upgradeLv: return this.upgradeLv;
			case E_CDEquipmentUpgrade.costItem: return this.costItem;
			case E_CDEquipmentUpgrade.costNum: return this.costNum;
			case E_CDEquipmentUpgrade.strengthenReduceLow: return this.strengthenReduceLow;
			case E_CDEquipmentUpgrade.strengthenReduceUp: return this.strengthenReduceUp;
			case E_CDEquipmentUpgrade.successRate_2: return this.successRate_2;
			case E_CDEquipmentUpgrade.successRate_3: return this.successRate_3;
			case E_CDEquipmentUpgrade.successRate_4: return this.successRate_4;
			case E_CDEquipmentUpgrade.failDropGroup_2: return this.failDropGroup_2;
			case E_CDEquipmentUpgrade.failDropGroup_3: return this.failDropGroup_3;
			case E_CDEquipmentUpgrade.failDropGroup_4: return this.failDropGroup_4;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDEquipmentUpgrade.id: this.id = v; break;
			case E_CDEquipmentUpgrade.upgradeLv: this.upgradeLv = v; break;
			case E_CDEquipmentUpgrade.costItem: this.costItem = v; break;
			case E_CDEquipmentUpgrade.costNum: this.costNum = v; break;
			case E_CDEquipmentUpgrade.strengthenReduceLow: this.strengthenReduceLow = v; break;
			case E_CDEquipmentUpgrade.strengthenReduceUp: this.strengthenReduceUp = v; break;
			case E_CDEquipmentUpgrade.successRate_2: this.successRate_2 = v; break;
			case E_CDEquipmentUpgrade.successRate_3: this.successRate_3 = v; break;
			case E_CDEquipmentUpgrade.successRate_4: this.successRate_4 = v; break;
			case E_CDEquipmentUpgrade.failDropGroup_2: this.failDropGroup_2 = v; break;
			case E_CDEquipmentUpgrade.failDropGroup_3: this.failDropGroup_3 = v; break;
			case E_CDEquipmentUpgrade.failDropGroup_4: this.failDropGroup_4 = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDEquipmentUpgrade> = new HashMap<number, CDEquipmentUpgrade>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDEquipmentUpgrade[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDEquipmentUpgrade();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].upgradeLv = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costItem = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].strengthenReduceLow = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].strengthenReduceUp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].successRate_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].successRate_3 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].successRate_4 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].failDropGroup_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].failDropGroup_3 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].failDropGroup_4 = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDEquipmentUpgrade{
		return this.datas ? this.datas.get(id) : null;
	}
}
